# SDOF Supporting Structure for Validation of Non-structural Damping Models; kN, mm, s
wipe all;


source FMdata.tcl


wipe;
model BasicBuilder -ndm 2 -ndf 3;	# Define the model builder, ndm=#dimension, ndf=#dofs

source DynamicAnalysisSolver.tcl;

#Define Nodes


node 1 0.0 0.0;
node 2 0.0 0.0;
node 3 $width 0.0;
node 4 $width 0.0;
node 5 [expr $width/2] 0.0;
node 6 [expr $width/2] $height;
node 7 [expr $width/2] $height;

#node 8 [expr $width/2] [expr $height/2];

# assign boundary condidtions 
	# command:  fix nodeID dxFixity dyFixity rzFixity
	# fixity values: 1 = constrained; 0 = unconstrained
	fix 1 1 1 1;
	fix 3 1 1 1;
	
# assign mass to node 2
set Mass1 [expr 1*$M/1]; #in kNs^2/mm
#set Mass2 [expr $M/4]
set Negligible 1e-9;
#puts $Mass;

mass 7 $Mass1 $Mass1 $Negligible;
#mass 8 $Mass2 $Mass2 $Negligible; 

#Define Geometric Transformation
set Transf 1;
geomTransf Linear $Transf; 	# Geometric transformation

#Define Material 
set PI 3.1415;

set matID 5;
set eleID1 6;
set eleID2 7;
set eleID3 8;
set nodeR1 1;
set nodeC1 2;
set nodeR2 3;
set nodeC2 4;
set nodeR3 6;
set nodeC3 7;

uniaxialMaterial Hysteretic $matID $s1p $e1p $s2p $e2p $s3p $e3p -$s1n -$e1n -$s2n -$e2n -$s3n -$e3n $pinchX $pinchY $damage1 $damage2 $beta;
uniaxialMaterial Elastic 1 100;

uniaxialMaterial SelfCentering 10 $k1 $k2 $sigAct $betaf;				

## Using elastic beam elements

set A 1000000;
set E 210;
set Iz 83333333333;

element elasticBeamColumn 130 2 5 $A $E $Iz $Transf
element elasticBeamColumn 131 5 4 $A $E $Iz $Transf
element elasticBeamColumn 132 5 6 $A $E $Iz $Transf
#element elasticBeamColumn 132 8 6 $A $E $Iz $Transf

# ## Using rigid links

# rigidLink beam 2 5;
# rigidLink beam 5 4;
# rigidLink beam 5 6;

element zeroLength $eleID1 $nodeR1 $nodeC1 -mat 1 $matID -dir 1 2 -doRayleigh 1;
element zeroLength $eleID2 $nodeR2 $nodeC2 -mat 1 $matID -dir 1 2 -doRayleigh 1;

element zeroLength $eleID3 $nodeR3 $nodeC3 -mat 10 1 -dir 1 2 -doRayleigh 1;

equalDOF $nodeR3 $nodeC3 3;

#STATIC LOAD

set grav 9810.0;

set gravload [expr -$M*$grav];

pattern Plain 11 Linear {

load 7 0 $gravload 0

}


#Statica
constraints Plain
numberer RCM
system BandGeneral
test EnergyIncr 1.0e-3 500
algorithm Newton
integrator LoadControl 0.01
analysis Static
analyze 100
loadConst -time 0.0 

puts "Model Built"


set GMfact 1000.0;				# ground-motion scaling factor
set GMdirection 1;			# ground-motion direction

set DtAnalysis	$dtg;	# time-step Dt for lateral analysis
set TmaxAnalysis	$durs;	# maximum duration of ground-motion analysis -- should be 50*$sec


set omega {}
set freq {}
set perT {}

set lambda [eigen -fullGenLapack 2];

foreach lam $lambda {
	lappend omega [expr sqrt($lam)]
	lappend freq [expr sqrt($lam)/(2*$PI)]
	lappend perT [expr (2*$PI)/sqrt($lam)]
}

set T1 [lindex $perT 0];
set T2 [lindex $perT 1];
puts "T1 = $T1 s";									# display the first mode period in the command window
puts "T2 = $T2 s";		

set xDamp 0.02;					# damping ratio
set MpropSwitch 0.0;
set KcurrSwitch 1.0;
set KcommSwitch 0.0;
set KinitSwitch 0.0;

set alphaM [expr $MpropSwitch*$xDamp*(2*[lindex $omega 0])];	# M-prop. damping; D = alphaM*M
set xbetaKcurr [expr $KcurrSwitch*2.0*$xDamp/([lindex $omega 0])];         		# current-K;      +beatKcurr*KCurrent
set xbetaKcomm [expr $KcommSwitch*2.0*$xDamp/([lindex $omega 0])];   		# last-committed K;   +betaKcomm*KlastCommitt
set xbetaKinit [expr $KinitSwitch*2.0*$xDamp/([lindex $omega 0])];         			# initial-K;     +beatKinit*Kini
# define damping
rayleigh $alphaM $xbetaKcurr $xbetaKinit $xbetaKcomm;  	

set IDloadTag 400;	# for uniformSupport excitation
set IDtimeS 10;     #for ground acceleration time history
# Uniform EXCITATION: acceleration input
		#set inFileH $GMfile.at2
		#ReadRecord $inFileH $outFileH dt nPt;		# call procedure to convert the horizontal ground-motion file
set GMfatt $GMfact;		# data in input file is in m/s2 Unifts -- ACCELERATION TH

timeSeries Path $IDtimeS  -fileTime $FMfilet -filePath $FMfilea -factor  $GMfatt;
pattern UniformExcitation  $IDloadTag  $GMdirection -accel  $IDtimeS;		# create Unifform excitation

# recorder EnvelopeNode -file [format "Results/DispE%d.out" $snumber] -time -node 2 -dof 1 disp;
recorder Node -file "ResultsAtt/AccelT.out" -timeSeries $IDtimeS -time -node 7 -dof 1 accel;
recorder Node -file "ResultsAtt/AccelrelT.out" -time -node 7 -dof 1 accel;
recorder Node -file "ResultsAtt/DispT.out" -time -node 7 -dof 1 disp;
recorder Node -file "ResultsAtt/UpliftT.out" -time -node 2 4 -dof 2 disp;
recorder Node -file "ResultsAtt/ForceT.out" -time -node 1 3 -dof 1 2 reaction;


puts "Running Floor Motion";

DynamicAnalysisSolver $DtAnalysis $TmaxAnalysis 1.0e-3;

record















